package org.gnut.tinyurl.portlet.servlet;

import javax.portlet.PortalContext;
import javax.portlet.PortletRequest;
import javax.servlet.http.HttpServletRequest;

public class RemoteBuilder {
	public static final String JETSPEED_REMOTEPROVIDER="org.gnut.tinyurl.portal.jetspeed.RemoteProvicderImpl";
	public static RemoteProvider getProvider(PortletRequest portletRequest,HttpServletRequest httpServletRequest){
		PortalContext portalContext =  portletRequest.getPortalContext();
		String portalInfo =portalContext.getPortalInfo();
		if(portalInfo!=null&&portalInfo.indexOf("Jetspeed")>=0){
			Class clazz;
			try {
				clazz = Class.forName(JETSPEED_REMOTEPROVIDER);
				RemoteProvider provider = (RemoteProvider) clazz.newInstance();
				provider.setHttpServletRequest(httpServletRequest);
				provider.setPortletRequest(portletRequest);
				return provider;
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		RemoteProvider provider = new DefaultRemoteProvider();
		provider.setHttpServletRequest(httpServletRequest);
		provider.setPortletRequest(portletRequest);
		return provider;
	}
}
